package com.crm.common.util;

import com.crm.common.constant.ProjectBusinessConstant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @author yincuimei
 * @Date 2021/4/8 10:32
 */
@Configuration
public class PathUtil {
    private static String separator = System.getProperty("file.separator");

    private static String winPath;

    private static String linuxPath;

    private static String winIp;

    private static String linuxIp;

    private static String accessPath;

    private static String port;

    private static String downPath;

    @Value("${server.port}")
    public void setServerPort(String port) {
        PathUtil.port = port;
    }

    @Value("${win.base.path}")
    public void setWinPath(String winPath) {
        PathUtil.winPath = winPath;
    }

    @Value("${linux.base.path}")
    public void setLinuxPath(String linuxPath) {
        PathUtil.linuxPath = linuxPath;
    }

    @Value("${file.staticAccessPath}")
    public void setAccessPath(String accessPath){
        PathUtil.accessPath = accessPath;
    }

    @Value("${crm.win.ip}")
    private void setWinIp(String winIp){
        PathUtil.winIp = winIp;
    }

    @Value("${crm.linux.ip}")
    private void setLinuxIp(String linuxIp){
        PathUtil.linuxIp = linuxIp;
    }

    @Value("${linux.base.down}")
    private void setDownPath(String downPath){
        PathUtil.downPath = downPath;
    }

    public static String getPort(){
        return port;
    }

    public static String getBasePath() {
        String os = System.getProperty("os.name");
        String basePath = "";
        if (os.toLowerCase().startsWith("win")) {
            basePath = winPath;
        } else {
            basePath = linuxPath;
        }
        return basePath;
    }

    public static String getCrmIp(){
        String os = System.getProperty("os.name");
        String crmIp = "";
        if (os.toLowerCase().startsWith("win")) {
            crmIp = winIp;
        } else {
            crmIp = linuxIp;
        }
        return crmIp;
    }

    public static String getDownPath(){
        String os = System.getProperty("os.name");
        String crmIp = "";
        if (os.toLowerCase().startsWith("win")) {
            crmIp = "static/excelTemplate/";
        } else {
            crmIp = downPath;
        }
        return crmIp;
    }

    public static String getAccessPath(){
        String staticAccessPath = accessPath.replace("*","");
        return staticAccessPath;
    }

    /**
     * 获取合同相关path
     * @return
     */
    public static String getContractPath() {
        return ProjectBusinessConstant.CONTRACT_RELEVANT_ITEM_PATH;
    }
}
